<layout name="master"/>
<script src="__PUBLIC__/js/jquery.min.js"></script>
<script src="__PUBLIC__/uploadify/jquery.uploadify.js"></script>
<link rel="stylesheet" href="__PUBLIC__/uploadify/uploadify.css">
<!--百度编辑器-->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>

<ul class="breadcrumb no-border no-radius b-b b-light pull-in">
    <li><a href="index.html"><i class="fa fa-home"></i> Home</a></li>
    <li><a href="#">商品管理</a></li>
    <li class="active">商品添加</li>
</ul>
<div class="col-sm-12">
    <section class="panel panel-default">
        <header class="panel-heading font-bold">商品添加</header>
        <div class="panel-body">
            <form method="post" action="" class="bs-example form-horizontal" enctype="multipart/form-data">
                <table class="table table-hover">
                    <tbody>
                    <tr>
                        <td width="20%">分类</td>
                        <td width="80%">
                            <select name="tid" id="">
                                <option value="0">请选择分类</option>
                                <volist  name="cateTree" id="ct">
                                    <option cid="{$ct['cid']}" <if condition="$ct['pid']==0">disabled</if> value="{$ct['tid']}">{$ct['_cname']}</option>
                                </volist>
                            </select>
                            <input type="hidden" name="cid" value="0">
                        </td>
                    </tr>
                    <tr>
                        <td>品牌</td>
                        <td>
                            <select name="bid" id="">
                                <volist name="brandList" id="bl">
                                    <option value="{$bl['bid']}">{$bl['bname']}</option>
                                </volist>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>商品名</td>
                        <td>
                            <input type="text" name="gname" class="form-control">
                        </td>
                    </tr>
                    <tr>
                        <td>货号</td>
                        <td>
                            <input type="text" name="gnumber" class="form-control">
                        </td>
                    </tr>
                    <tr>
                        <td>记件单位</td>
                        <td>
                            <input type="text" name="unit" class="form-control" value="件">
                        </td>
                    </tr>
                    <tr>
                        <td>市场价</td>
                        <td>
                            <input type="text" name="marketprice" class="form-control" value="0">
                        </td>
                    </tr>
                    <tr>
                        <td>商城价</td>
                        <td>
                            <input type="text" name="shopprice" class="form-control" value="0">
                        </td>
                    </tr>
                    <tr>
                        <td>普通属性</td>
                        <td id="GoodsAttrBox">

                        </td>
                    </tr>
                    <tr>
                        <td>规格</td>
                        <td id="GoodsSpecBox">

                        </td>
                    </tr>
                    <tr>
                        <td>列表图</td>
                        <td>
                            <button id="thumb"></button>
                            <div id="thumbBox"></div>
                        </td>
                    </tr>
                    <tr>
                        <td>商品图册</td>
                        <td>
                            <button id="ggPic"></button>
                            <div id="ggPicBox"></div>
                        </td>
                    </tr>
                    <tr>
                        <td>点击次数</td>
                        <td>
                            <input type="text" name="click" class="form-control" value="0">
                        </td>
                    </tr>
                    <tr>
                        <td>库存</td>
                        <td>
                            <input type="text" name="total" class="form-control" value="0">
                        </td>
                    </tr>
                    <tr>
                        <td>商品详情</td>
                        <td>
                            <textarea style="width:100%" id="intro" name="intro" cols="30" rows="10"></textarea>
                            <!-- 实例化编辑器 -->
                            <script type="text/javascript">
                                var ue = UE.getEditor('intro');
                            </script>
                        </td>

                    </tr>
                    <tr>
                        <td>售后服务</td>
                        <td>
                            <textarea style="width:100%" id="service" name="service" cols="30" rows="10"></textarea>
                            <!-- 实例化编辑器 -->
                            <script type="text/javascript">
                                var ue = UE.getEditor('service');
                            </script>
                        </td>
                    </tr>
                    <tr>
                        <th colspan="2">
                            <input type="submit" value="保存" class="btn btn-success btn-block">
                        </th>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </section>
</div>
</div>

<script>
    $(function () {
        $("#thumb").uploadify({
            buttonText: '上传',
            buttonClass: 'bgred',
            height: 30,
            swf: '__PUBLIC__/uploadify/uploadify.swf',
            uploader: "{:u('admin/goods/ajaxUpload',['tpl'=>'thumb'])}",
            width: 120,
            onUploadSuccess: function (file, data, response) {
                $('#thumbBox').append(data);
            }
        });

        $("#ggPic").uploadify({
            buttonText: '上传',
            buttonClass: 'bgred',
            height: 30,
            swf: '__PUBLIC__/uploadify/uploadify.swf',
            uploader: "{:u('admin/goods/ajaxUpload',['tpl'=>'ggPicTpl'])}",
            width: 120,
            onUploadSuccess: function (file, data, response) {
                $('#ggPicBox').append(data);
            }
        });
    });

    $('[name=tid]').change(function(){
        var tid = $(this).val();
        var cid = $(this).find('option:selected').attr('cid');
        $('input[name=cid]').val(cid);
        //获得普通属性模板
        $.get("{:u('admin/goods/getGoodsAttr')}",{tid:tid,class:0,tpl:'goodsAttrTpl'},function(data){
            $('#GoodsAttrBox').html(data);
        })
        //获得规格模板
        $.get("{:u('admin/goods/getGoodsAttr')}",{tid:tid,class:1,tpl:'goodsSpecTpl'},function(data){
            $('#GoodsSpecBox').html(data);
        })
    });

</script>